// import 'package:amap_base/amap_base.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
//import 'package:wanchong/app/store/amap.dart';
import 'package:wanchong/conf.dart';
import 'package:wanchong/utils/common.dart';

class StoreDetails extends StatefulWidget {
  final String id;
  StoreDetails({Key key, @required this.id});
  @override
  _StoreDetailsState createState() => _StoreDetailsState();
}

class _StoreDetailsState extends State<StoreDetails> {
  List<String> imgs = [];
  List<TagInfo> tags = [];
  List<String> services = [];
  @override
  void initState() {
    super.initState();
    imgs.add(
        "http://img.redocn.com/sheji/20141219/zhongguofengdaodeliyizhanbanzhijing_3744115.jpg");
    imgs.add("http://pic32.nipic.com/20130810/7772606_170808427000_2.jpg");
    imgs.add("http://pic41.nipic.com/20140508/18609517_112216473140_2.jpg");
    tags.add(TagInfo(
        url: "https://www.easyicon.net/download/png/1178853/72/",
        content:
            "营业：周一至周五\t\t\t\t全天,\r\n \t\t\t\t\t\t\t\t\t\t周六至周日\t\t\t\t00:00 ~ 23:30啊哈哈哈哈哈哈哈"));
    tags.add(TagInfo(
        url: "https://www.easyicon.net/download/png/1178853/72/",
        content: "免费WiFi、付费停车位"));
    services.add("纯享泡泡浴基础SPA");
    services.add("精致洗澡美容");
    services.add("小型犬猫寄养");
    services.add("犬猫洁牙");
    // tags.add(TagInfo(
    //     url: "https://www.easyicon.net/download/png/1178853/72/",
    //     content: "天府二街建发·鹭洲里西广场负一层下沉式广场（百弗英语、造物圈）"));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0.0,
        automaticallyImplyLeading: false,
        // leading: GestureDetector(child: Container(),),
        title: Container(
            width: double.infinity,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                GestureDetector(
                  onTap: () {
                    Navigator.of(context).pop();
                  },
                  child: Icon(
                    Icons.chevron_left,
                    size: 24.0,
                  ),
                ),
                GestureDetector(
                  child: Icon(
                    Icons.share,
                    size: 24.0,
                  ),
                ),
              ],
            )),
      ),
      body: Container(
        color: Colors.white,
        child: ListView(
          physics: BouncingScrollPhysics(),
          // color: Colors.white,
          children: [
            Container(
              // color: Colors.white,
              // height: 240.0,
              width: double.infinity,
              child: Swiper(
                itemBuilder: (BuildContext context, int index) {
                  return ClipRRect(
                    child: CachedNetworkImage(
                      imageUrl: imgs[index],
                      fit: BoxFit.cover,
                    ),
                    borderRadius: BorderRadius.circular(5.0),
                  );
                },
                autoplay: true,
                itemCount: 3,
                itemWidth: double.infinity,
                itemHeight: 220.0,
                layout: SwiperLayout.TINDER,
              ),
            ),
            SizedBox(
              height: ScreenUtil.getInstance().setHeight(15.0),
            ),
            Container(
              // color: Colors.red,
              width: double.infinity,
              margin: EdgeInsets.only(
                left: 15.0,
                right: 15.0,
              ),
              child: Column(
                children: <Widget>[
                  SizedBox(
                    height: ScreenUtil.getInstance().setHeight(20.0),
                  ),
                  Container(
                    width: double.infinity,
                    child: Text(
                      "HIDE&SEEK宠物猫舍",
                      // textAlign: TextAlign.start,
                      style: TextStyle(
                        color: Color(MainColor),
                        fontSize: ScreenUtil.getInstance().setSp(24.0),
                      ),
                    ),
                  ),
                  SizedBox(
                    height: ScreenUtil.getInstance().setHeight(15.0),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      // SizedBox(),
                      Text(
                        "华阳 宠物医院",
                        style: TextStyle(
                          fontSize: ScreenUtil.getInstance().setSp(14.0),
                          color: Color(0xFF647280),
                        ),
                      ),
                      Text(
                        "免费wifi,付费停车场",
                        style: TextStyle(
                          fontSize: ScreenUtil.getInstance().setSp(12.0),
                          color: Color(0xFFB4BEC6),
                        ),
                      ),
                    ],
                  ),
                  SizedBox(
                    height: ScreenUtil.getInstance().setHeight(20.0),
                  ),
                  Column(
                    children: tags.map((TagInfo info) {
                      return _tag(info.url, info.content);
                    }).toList(),
                  ),
                  _location("https://www.easyicon.net/download/png/1178853/72/",
                      "天府二街建发·鹭洲里西广场负一层下沉式广场（百弗英语、造物圈）")
                ],
              ),
            ),
            Container(
              color: Color(0xFFFAFAFA),
              height: 15.0,
            ),
            Container(
              width: double.infinity,
              margin: EdgeInsets.only(
                left: 15.0,
                right: 15.0,
              ),
              child: Column(
                children: <Widget>[
                  Container(
                    width: double.infinity,
                    padding: EdgeInsets.only(top: 15),
                    child: Text(
                      "提供服务",
                      style: TextStyle(color: Color(MainColor), fontSize: 14),
                    ),
                  ),
                  ...List.generate(
                      services.length, (int index) => _service(index)).toList(),
                ],
              ),
            ),
            GestureDetector(
              onTap: () {
                // alert("预约打电话");
                launchPhone(phone:"13993463312");
              },
              child: Container(
                color: Colors.transparent,
                width: double.infinity,
                height: 50.0,
                child: Center(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(right: 8),
                        width: 15,
                        height: 15,
                        child: Image.asset(
                          "assets/store/shop_phone_icon.png",
                          fit: BoxFit.cover,
                        ),
                      ),
                      Text(
                        "电话预约",
                        style:
                            TextStyle(color: Color(0xFF4DC975), fontSize: 14.0),
                      )
                    ],
                  ),
                ),
              ),
            ),
            SizedBox(
              height: 30.0,
            ),
          ],
        ),
      ),
    );
  }

  Widget _location(String url, String content) {
    return Container(
      margin: EdgeInsets.only(
          top: ScreenUtil.getInstance().setHeight(10.0),
          bottom: ScreenUtil.getInstance().setHeight(10.0)),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            width: 15.0,
            height: 15.0,
            child: CachedNetworkImage(
              imageUrl: url,
              fit: BoxFit.cover,
            ),
          ),
          SizedBox(
            width: 5.0,
          ),
          Expanded(
            child: Container(
              child: Text(
                content,
                softWrap: true,
                style: TextStyle(
                  color: Color(0xFF647280),
                  fontSize: ScreenUtil.getInstance().setSp(14.0),
                ),
              ),
            ),
          ),
          Container(
            alignment: Alignment.center,
            color: Colors.transparent,
            padding: EdgeInsets.all(15),
            child: GestureDetector(
              onTap: () {
                // Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context)=>AmapPage()));
                // AMapNavi().startNavi(
                //   lat: 30.618,
                //   lon: 104.097,
                //   naviType: AMapNavi.ride,
                // );
              },
              child: Center(
                child: Container(width: 20,height: 20,child: Image.asset("assets/store/shop_daohang_icon.png"),),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _tag(String url, String context) {
    return Container(
      margin: EdgeInsets.only(
          top: ScreenUtil.getInstance().setHeight(10.0),
          bottom: ScreenUtil.getInstance().setHeight(10.0)),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            width: 15.0,
            height: 15.0,
            child: CachedNetworkImage(
              imageUrl: url,
              fit: BoxFit.cover,
            ),
          ),
          SizedBox(
            width: 5.0,
          ),
          Expanded(
            child: Container(
              child: Text(
                context,
                softWrap: true,
                style: TextStyle(
                  color: Color(0xFF647280),
                  fontSize: ScreenUtil.getInstance().setSp(14.0),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _service(int index) {
    return Container(
      padding: EdgeInsets.only(top: 10, bottom: 10),
      child: Row(
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(right: 12),
            width: 15,
            height: 15,
            child: Image.asset(
              "assets/store/shop_service_icon_qizhi.png",
              fit: BoxFit.cover,
            ),
          ),
          Text(
            services[index],
            style: TextStyle(
              color: Color(0xFF647280),
              fontSize: 14.0,
            ),
          )
        ],
      ),
    );
  }
}

class TagInfo {
  String url;
  String content;
  TagInfo({this.url, this.content});
}
